<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <script src="./js/03-ajax.js"></script>
  <script>
    // new Promise((resolve, reject) => {
    //   throw new Error('fail')
    // }).catch(error => {
    //   console.log(error.message)
    // })

    // async function fn() {
    //   console.log(a)
    // }
    // fn().catch(error => {
    //   console.log('Error--' + error)
    // })

    // function fn(name) {
    //   return ajax(`http://localhost:3000/profile1?${name}`)
    // }
    // fn('lisa')
    //   .then(value => console.log(value))
    //   .catch(error => {
    //     console.log('Error--' + error)
    //   })

    // async function fn2(name) {
    //   let user = await ajax(`http://localhost:3000/profile?${name}`)
    //   return user
    // }
    // fn2('lisa').then(value => console.log(value))
    //   .catch(error => {
    //     console.log('Error--' + error)
    //   })

    async function fn2(name) {
      try {
        let user = await ajax(`http://localhost:3000/profile1?${name}`)
        return user
      } catch (error) {
        console.log(error.message)
      }
      console.log(3) // 错误处理后这里还是会继续执行的
    }
    fn2('lisa').then(value => console.log(value))
    // .catch(error => console.log(error))
  </script>
</body>
</html>